//index.js
//获取应用实例
const config = require("../../config/config.js")
var timer = null;
var timeOut = null;

Page({
    data: {
        showVideo: false,
        companyList: [],
        showLookMore: false,
        videoSrc: config.vedioSrc,
        indicatorStatus: 1,
        videoContext: null,
        scrollToIndex: 0,
        height: 0,
        scrollTop: 0,
    },
    onLoad: function () {
        var companyList = config.componyList;
        if (companyList.length > 6) {
            this.setData({
                companyList: companyList,
                showLookMore: true
            })
        } else {
            this.setData({
                companyList: companyList,
                showLookMore: false
            })
        }
        this.autoScroll()
    },
    onReady: function () {
        this.videoContext = wx.createVideoContext('myVideo')
    },
    autoScroll() {
        //   var i = 0;
        //   var _this = this
        //   var length = this.data.companyList.length;
        //   timer = setInterval(function () {
        //       if (i < length - 6) {
        //           _this.setData({
        //               scrollToIndex: i
        //           })
        //           i++;
        //       } else {
        //           i = 0;
        //           _this.setData({
        //               scrollToIndex: i
        //           })
        //           i++;
        //       }

        //   }.bind(this), 1500)

        var height = this.data.height;
        var scrollTop = this.data.scrollTop;
        var isTouch = this.data.isTouch;
        timer = setInterval(function () {
            if ((scrollTop < height || scrollTop == 0)) {
                this.setData({
                    scrollTop: this.data.scrollTop + 25
                })
            }
        }.bind(this), 1500)
    },
    bindscroll(e) {
        console.log('ting', e.detail.deltaY)
        var deltaY = e.detail.deltaY
        //   this.setData({
        //       isTouch: true
        //   })
        //   clearInterval(timer)
        //   this.setData({
        //       scrollTop: e.detail.scrollTop,
        //       height: e.detail.scrollHeight
        //   })
        //   this.autoScroll();
        //   if(timer){
        //     clearInterval(timer)
        //   }
        if (deltaY == -25) {//自动滚动

        } else {//手动滚动
            clearInterval(timer)
            // this.setData({
            //     scrollTop: e.detail.scrollTop,
            //     height: e.detail.scrollHeight
            // })
            // timeOut = setTimeout(function(){

            // }.bind(this), 2000)
        }
    },
    //监听swiper的滑动
    listenSwiperChange(e) {
        if (e.detail.current == 2) {
            setTimeout(function () {
                this.setData({
                    showVideo: true,
                    indicatorStatus: e.detail.current + 1
                })
            }.bind(this), 500)
            //   this.videoContext.play()
        } else {
            //   setTimeout(function(){
            this.setData({
                showVideo: false,
                indicatorStatus: e.detail.current + 1
            })
            //   }.bind(this), 500)
            this.videoContext.pause()
        }
    },
    //查看更多
    lookMore() {
        wx.navigateTo({
            url: '../lookmore/lookmore'
        })
    },
    //跳转到参与代言页面
    goPartake() {
        wx.navigateTo({
            url: '../partake/partake'
        })
    },
    touchstartFn(e) {
        console.log('???')
        console.log('开始 ', e)
    },
    touchmoveFn(e) {
        console.log('移动 ', e)
    },
    touchendFn(e) {
        console.log('结束 ', e)
    },
    hh() {
        console.log('xxx')
    }
})
